//
//  AddressEditView.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/4/14.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "AddressEditView.h"

@interface AddressEditView ()

@property (nonatomic, strong) UILabel *defaultLab;
@property (nonatomic, strong) UIView *sep;
@property (nonatomic, strong) UIButton *editButton;

@end

@implementation AddressEditView

- (void)clickAcion:(id)sender
{
    if (self.editHandler) {
        self.editHandler();
    }
}

- (void)setIsDefalut:(BOOL)isDefalut
{
    _isDefalut = isDefalut;
    self.defaultLab.hidden = !isDefalut;
}

- (void)setupSubViews
{
    self.nameLab = [[UILabel alloc] init];
    self.nameLab.font = [UIFont systemFontOfSize:16];
    self.nameLab.textColor = kColor333333;
    [self addSubview:self.nameLab];
    self.nameLab.text = @"张艺兴";
    
    self.telLab = [[UILabel alloc] init];
    self.telLab.font = [UIFont systemFontOfSize:14];
    self.telLab.textColor = kColor666666;
    [self addSubview:self.telLab];
    self.telLab.text = @"15516979760";
    
    self.defaultLab = [[UILabel alloc] init];
    self.defaultLab.textAlignment = NSTextAlignmentCenter;
    self.defaultLab.font = [UIFont systemFontOfSize:11];
    self.defaultLab.textColor = [UIColor whiteColor];
    [self addSubview:self.defaultLab];
    self.defaultLab.backgroundColor = UIColorFromRGB(0x1975FF);
    self.defaultLab.text = @"默认";
    self.defaultLab.hidden = YES;
    
    self.addressLab = [[UILabel alloc] init];
    self.addressLab.numberOfLines = 2;
    self.addressLab.font = [UIFont systemFontOfSize:14];
    self.addressLab.textColor = kColor333333;
    [self addSubview:self.addressLab];
    self.addressLab.text = @"深圳市宝安区翻身路金岸雅苑23栋401";
    self.addressLab.backgroundColor = [UIColor clearColor];
    
    self.sep = [[UIView alloc] init];
    self.sep.backgroundColor = kColorDDD;
    [self addSubview:self.sep];
    
    self.editButton = [[UIButton alloc] init];
    [self.editButton setTitle:@"编辑" forState:UIControlStateNormal];
    [self.editButton setTitleColor:kColor666666 forState:UIControlStateNormal];
    self.editButton.titleLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:self.editButton];
    
    [self.editButton addTarget:self action:@selector(clickAcion:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setupConstraints
{
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.top.equalTo(self).offset(20);
    }];
    
    [self.telLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLab.mas_right).offset(10);
        make.centerY.equalTo(self.nameLab);
        make.right.lessThanOrEqualTo(self).offset(-10);
    }];
    
    [self.defaultLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLab);
        make.top.equalTo(self.nameLab.mas_bottom).offset(16);
        make.width.equalTo(@31);
        make.height.equalTo(@(16));
    }];
    
    [self.addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLab.mas_bottom).offset(16);
        make.left.equalTo(self.nameLab);
        make.right.lessThanOrEqualTo(self.sep.mas_left).offset(-10);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    [self.sep mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-60);
        make.height.equalTo(@20);
        make.width.equalTo(@1);
    }];
    
    [self.editButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.sep.mas_right);
        make.right.equalTo(self);
        make.top.bottom.equalTo(self);
    }];
    
}

@end
